package org.gaojianqiao.electronichandbook.database;

import java.io.UnsupportedEncodingException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import org.gaojianqiao.electronichandbook.createtable.History;

import zyg.login.DataBas;

public class OperateHistory
{
	public void createtable( ) throws SQLException, ClassNotFoundException
	{

		String sql2 = "drop table if exists History";
		String sql3 = "create table History (Tablename text,Tableid text)";
		DataBas publicDataBase = new DataBas();
		Connection conn = publicDataBase.connectDB("data3");
		Statement stat = conn.createStatement();
		conn.setAutoCommit(false);
		stat.executeUpdate(sql2);
		stat.executeUpdate(sql3);
		conn.commit();
		conn.close();
	}

	public ArrayList<History> Historylist(String bookName) throws SQLException,
			UnsupportedEncodingException
	{

		// TODO Auto-generated method stub

		String sql = "select * from " + bookName;
		DataBas publicDataBase = new DataBas();
		publicDataBase.connectDB("public");
		ResultSet rs = publicDataBase.stmt.executeQuery(sql);
		ArrayList<History> HistoryList = new ArrayList<History>();
		while (rs.next())
		{
			History Hist = new History();
			Hist.setTablename(rs.getString("Tablename"));
			Hist.setTableid(rs.getString("Tableid"));
		}
		publicDataBase.closeDB();

		return HistoryList;
	}

}
